package com.kstech.ks_gaz01.data

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.kstech.ks_gaz01.databinding.LayoutItemBinding

/**
 * author: lenovo
 * created on: 2023/12/19 10:55
 * description:
 */
class DebugDataItemAdapter : BaseQuickAdapter<DebugDataBean.Item, DebugDataItemAdapter.VH>() {
    // 自定义ViewHolder类
    private var mContext: Context? = null
    class VH(
        parent: ViewGroup,
        val binding: LayoutItemBinding = LayoutItemBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        )
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder
        mContext = context
        return VH(parent)
    }

    override fun onBindViewHolder(
        holder: VH, position: Int, item: DebugDataBean.Item?
    ) {
        holder.binding.itemAddress.text = item!!.para0 //地址
        holder.binding.itemName.text = item!!.para1//项目名
//        if (HardwareInfoUtil.getDpiString(mContext as Activity).contains("xxhdpi")) {
//            holder.binding.itemName.textSize = 16f
//        }else{
//            if (item!!.para1.length > 11) {
//                holder.binding.itemName.textSize = 17f
//            } else {
//                holder.binding.itemName.textSize = 22f
//            }
//        }

        holder.binding.unit.text = item!!.para5//单位
        holder.binding.value.text = item.revData//从控制器接收的参数
        if (item.writeRes) {
            holder.binding.writeRes.visibility = View.VISIBLE
        } else {
            holder.binding.writeRes.visibility = View.GONE
        }
    }
}
